package com.parttimetask.activities;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.parttimetask.databinding.ActivityCorpImgBinding;
import com.parttimetask.utils.crop.ImageToolUtils;


public class CropImgActivity extends AppCompatActivity {
    private String filePath;//需要剪裁的图片路径
    private ActivityCorpImgBinding binding;
    private String fileName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding= ActivityCorpImgBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        Intent intent = getIntent();
        filePath = intent.getStringExtra("path");
        fileName = intent.getStringExtra("filename");
        initView();
        setTitle("corp");
    }
    private void initView() {
        binding.cropCropImage.setAspectRatio(1,1);
        binding.cropCropImage.setFixedAspectRatio(true);
        binding.cropSure.setOnClickListener(v -> {
            //确定剪裁
            Bitmap bit = binding.cropCropImage.getCroppedImage();
            //压缩图片
            ImageToolUtils.compressBitmap(bit, ImageToolUtils.getCropdFilePath(CropImgActivity.this,fileName), 500);
            setResult(RESULT_OK);
            finish();
        });
        binding.cropCancel.setOnClickListener(v -> finish());
        Bitmap bitmap = ImageToolUtils.getBitmapFromFile(filePath);
        binding.cropCropImage.setImageBitmap(bitmap);
    }
}
